<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>房间管理</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/dtree.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/font/iconfont.css"/>
</head>
<style type="text/css">
    body, html {
        width: 100%;
        height: 100%;
    }
</style>
<body>
<div class="maintree">
    <div class="shoubtn switchbtn"><i class="iconfont">&#xe628;</i><i class="iconfont hide">&#xe939;</i></div>
    <div class="maintree-left">
        <div class="mainltree-left-tit">
            班级详情
        </div>
        <ul id="demoTree" class="dtree" data-id="0">
        </ul>
    </div>
    <div class="maintree-right">
        <div class="wrap-container clearfix">
            <div class="column-content-detail padt10">
                <!--右侧内容部分开始-->
                <form class="layui-form">
                    <div class="search-cont clearfix" id="tool">
                        <div class="operation-btn-cont" id="buttonDetail">

                        </div>
                        <div class="search-details">
                            <div class="layui-form-item marb5" id="searchDetail">
                            </div>
                        </div>
                    </div>
                </form>
                <div class="layui-form" id="table-list">
                    <table id="entityList" lay-filter="entityList" class="cy-list-table"></table>
                </div>
                <!--右侧内容部分结束-->
            </div>
        </div>
    </div>
</div>

<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    //Demo
    var applyId = '${applyId}';
    var divideId = '${divideId}';
    var tableIns = null;
    var parentId = '';
    var resultStatus='${resultStatus}';
    layui.use(['form', 'dialog', 'jquery', 'dtreeUtil', 'dtree', 'page', 'table', 'upload'], function () {
        var form = layui.form
            , $ = layui.jquery
            , dialog = layui.dialog
            , dtree = layui.dtree,
            page = layui.page,
            table = layui.table,
            upload = layui.upload
            , dtreeUtil = layui.dtreeUtil;
        $("#demoTree").html("");
        var renderTable = function () {
            $("#buttonDetail").html(" <button class='layui-btn layui-btn-normal layui-btn-mid' type='button'  onclick='exprotStudent()'><i class='iconfont marr5'>&#xe612;</i>导出</button>\
                    <button class='layui-btn layui-btn-normal layui-btn-mid' type='button' onclick='changeClass()'><i class='iconfont marr5'>&#xe612;</i>批量调班</button>\
                    <button class='layui-btn layui-btn-normal layui-btn-mid' type='button' onclick='fb()'><i class='iconfont marr5'>&#xe612;</i>结果发布</button>\
                    <div class='operright cyt-retract-close hideMenu'> 收起筛选<i class='iconfont'>&#xe658;</i></div>\
                    <div class='operright cyt-retract-open showMenu' style='display: none;'> 展开筛选<i class='iconfont'>&#xe936;</i></div>\
                    <div class='triangle-bottom'></div>\
                        <div class='triangle-top'></div>");
            $("#searchDetail").html("<div class='layui-inline'>\
                    <label class='layui-form-label'>学号：</label>\
                    <div class='layui-input-inline'>\
                        <input type='text' name='xh'  placeholder='请输入学号' autocomplete='off' class='layui-input'>\
                        </div>\
                        </div>\
                        <div class='layui-inline'>\
                        <label class='layui-form-label'>姓名：</label>\
                    <div class='layui-input-inline'>\
                        <input type='text' name='name'  placeholder='请输入姓名' autocomplete='off' class='layui-input'>\
                        </div>\
                        </div><div class='layui-inline marl8'>\
                    <button class='layui-btn layui-btn-normal' type='button' lay-submit='' lay-filter='seacherBtn'>搜索</button>\
                        <button class='layui-btn layui-btn-normal' type='reset'>重置</button>\
                        </div>");
            page.initDict('roomType,sexType', function (dictData) {
                var url = "/divideclass/divideclassstudent/page?applyId=" + applyId + "&classId=" + parentId;
                var cols = [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'xh', title: '学号', align: 'center'},
                    {field: 'name', title: '姓名', align: 'center'},
                    {
                        field: 'sex', title: '性别', align: 'center', templet: function (d) {
                        return page.aceeptDictContentName(dictData, 'sexType', d.sex);
                    }
                    },
                    {field: 'totalScore', title: '总分', align: 'center'},
                    {field: 'school', title: '来源学校', align: 'center'}
                ];
                tableIns = page.initDate(cols, url);
            });
        };
        var renderclassTable = function () {
            $("#buttonDetail").html(" <button class='layui-btn layui-btn-normal layui-btn-mid' type='button'  onclick='exportClass()'><i class='iconfont marr5'>&#xe612;</i>导出</button>\
            <button class='layui-btn layui-btn-normal layui-btn-mid' type='button' onclick='fb()'><i class='iconfont marr5'>&#xe612;</i>结果发布</button>\
                    <div class='operright cyt-retract-close hideMenu'> 收起筛选<i class='iconfont'>&#xe658;</i></div>\
                    <div class='operright cyt-retract-open showMenu' style='display: none;'> 展开筛选<i class='iconfont'>&#xe936;</i></div>\
                    <div class='triangle-bottom'></div>\
                        <div class='triangle-top'></div>");
            $("#searchDetail").html("<div class='layui-inline'>\
                    <label class='layui-form-label'>班级：</label>\
                    <div class='layui-input-inline'>\
                        <input type='text' name='name'  placeholder='请输入班级' autocomplete='off' class='layui-input'>\
                        </div>\
                        </div><div class='layui-inline marl8'>\
                    <button class='layui-btn layui-btn-normal' type='button' lay-submit='' lay-filter='seacherBtn'>搜索</button>\
                        <button class='layui-btn layui-btn-normal' type='reset'>重置</button>\
                        </div>");
            page.initDict('roomType,sexType', function (dictData) {
                var url = "/divideclass/divideclassclass/page?applyId=" + applyId + "&divideId=" + divideId;
                var cols = [
                    {type: 'numbers', title: '序号'},
                    {field: 'name', title: '班级', align: 'center'},
                    {field: 'num', title: '总人数', align: 'center'},
                    {field: 'bnum', title: '男生人数', align: 'center'},
                    {field: 'gnum', title: '女生人数', align: 'center'},
                    {field: 'average', title: '总均分', align: 'center'}
                ];
                tableIns = page.initDate(cols, url);
            });
        };
        dtreeUtil.pageDtree("#demoTree", "/divideclass/divideclass/dTreeListClass?applyId=" + applyId + "&divideId=" + divideId, false, function (data, obj) {
        });
        dtreeUtil.dTreeClick("demoTree", function (param) {
            parentId = param.nodeId;
            //获取分页数
            if (param.parentId === '0') {
                renderclassTable();
            } else {
                renderTable();
            }
        });
        renderclassTable();
    });
    function changeClass() {
        layui.use(['jquery', 'table', 'page', 'dialog', 'baseutil'], function () {
            var table = layui.table,
                dialog = layui.dialog,
                page = layui.page;
            var data = table.checkStatus('entityList').data;
            if (data.length === 0) {
                dialog.msg("请先选择对象");
                return false;
            } else {
                //批量调班
                var stuId = data[0].id;
                for (var i = 1; i < data.length; i++) {
                    stuId = stuId + "," + data[i].id;
                }
                page.editPopup('/divideclass/divideclassclass/getChangeClass?applyId=' + applyId + '&stuId=' + stuId+'&divideId='+divideId, '批量调班','560px','420px');
            }
        });
    }
    function exprotStudent() {
        window.location.href = "/work/divideclass/divideclassstudent/export?classId=" + parentId;
    }
    function exportClass() {
        window.location.href = "/work/divideclass/divideclassclass/export?divideId=" + divideId;
    }
    function fb(){
            layui.use(['jquery', 'table', 'page', 'dialog','baseutil'], function () {
                var baseutil=layui.baseutil,
                    dialog=layui.dialog;
                if(resultStatus==='0') {
                    baseutil.post("/divideclass/divideclass/fbResult", {id:divideId}, function (res) {
                        if(res.code==='0'){
                            $("#save").click();
                            dialog.msg("发布成功");
                        }else{
                            dialog.msg(res.msg);
                        }
                        return false;
                    });
                }else{
                    dialog.msg("该分班结果已发布，无法再次发布！");
                }

            });
    }
</script>
</body>
</html>